/*
 *    Alliciga's Process Partner Project
 * 
 *  Copyright (C) 2006-2011 Alliciga <alliciga@users.sourceforge.net>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 */

#include "../include/MonitorPolicy.h"

MonitorPolicy::MonitorPolicy()
{
	PolicyName = "BaseMonitorPolicy";
	NotifyMessage = "BaseMonitorPolicy Match";
}

MonitorPolicy::~MonitorPolicy()
{
	NotifyList.clear();
}

bool MonitorPolicy::AddNotificationPolicy(NotificationPolicy _np)
{
	NotifyList.push_front(_np);
	return true;
}

bool MonitorPolicy::DeleteNotificationPolicy(string name)
{
	bool ok = false;
	NotificationPolicyList::iterator r = NotifyList.begin();
	while(NotifyList.end() != r)
	{
		if(name == r->GetNotificationPolicyName())
		{
			NotifyList.erase(r);
			ok = true;
		}
		r++;
	}
	return ok;
}

list<string> MonitorPolicy::GetNotificationPolicyList()
{
	list<string> tmp;
	NotificationPolicyList::iterator r = NotifyList.begin();
	while(NotifyList.end() != r)
	{
		tmp.push_front(r->GetNotificationPolicyName());
		r++;
	}
	return tmp;
}

bool MonitorPolicy::Notify(MonitorProcess object)
{
	NotificationPolicyList::iterator r = NotifyList.begin();
	while(NotifyList.end() != r)
	{
		if(r->isAvailable())
		{
			r->Notify(object, NotifyMessage);
		}
		else
		{
			cout << r->GetNotificationPolicyName() << " is Not Available" << endl;
			return false;
		}
		r++;
	}
	return true;
}

bool MonitorPolicy::Match()
{
	return true;
}

// ---------End of File -------------
